import React from 'react'
import { useLocation,useParams} from 'react-router-dom';
import qs from 'qs';

export default function News() {
    const location = useLocation()

    const { user} = qs.parse(location.search.split("?")[1])

      //state可以拿到location中的数据
    const newsList = location.state

    // Params传参直接拿到路径中的id
    console.log(useParams());
    const {id}=  useParams()

  return (
    <div>
        <p>用户名是{user} 编号是:{id}</p>
        {
          newsList.map ((item)=>{
            return <li key={item.id}>{item.name}</li>
          })
        }
    </div>
  )
}
